package com.houhanzhi.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.houhanzhi.manager.TrafficTaskManager;
import com.houhanzhi.mapper.TrafficTaskMapper;
import com.houhanzhi.model.TrafficTaskDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TrafficTaskManagerImpl implements TrafficTaskManager {

    @Autowired
    private TrafficTaskMapper taskMapper;

    /**
     * 创建流量包任务
     *
     * @param trafficTaskDO
     * @return
     */
    @Override
    public int add(TrafficTaskDO trafficTaskDO) {
        return taskMapper.insert(trafficTaskDO);
    }

    /**
     * 查询流量包任务
     *
     * @param id        任务 id
     * @param accountNo 用户
     * @return
     */
    @Override
    public TrafficTaskDO findByIdAndAccountNo(Long id, Long accountNo) {
        return taskMapper.selectOne(new QueryWrapper<TrafficTaskDO>()
                .eq("id", id)
                .eq("account_no", accountNo));
    }

    /**
     * 删除任务
     *
     * @param id        任务 id
     * @param accountNo 用户
     * @return
     */
    @Override
    public int deleteByIdAndAccountNo(Long id, Long accountNo) {
        return taskMapper.delete(new QueryWrapper<TrafficTaskDO>()
                .eq("id", id)
                .eq("account_no", accountNo));
    }
}
